package cn.xtits.xtf.common.db.shard;

import cn.xtits.xtf.common.exception.XTDbShardException;
import org.apache.commons.lang.math.NumberUtils;
import org.springframework.util.Assert;

/**
 * Created by ShengHaiJiang on 16/4/5.
 */
public class UserDbShardStrategy implements XTDbShardStrategy {


    @Override
    public String defaultDbShard(Object shardKey) {
        Assert.notNull(shardKey);
        if (!NumberUtils.isNumber((String)shardKey)) throw new XTDbShardException("shardKey is not number!");
        long dbIndex = (NumberUtils.toLong((String)shardKey) / 1000) + 1;
        return "user_" + dbIndex;
    }
}
